package com.example.skinmanager

import android.content.Context
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.TextView
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import com.example.skinhelper.SkinIns
import java.util.ArrayList

class ListActivity : AppCompatActivity() {

    private var rv: RecyclerView? = null
    private var data = ArrayList<String>()
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_list)
//        Util.replaceActivityResources(this,SkinIns.getInstance().skinResources)
        rv = findViewById(R.id.rv_main)
        for (i in 0..20) {
            data.add("the $i data")
        }
        rv?.adapter = MyAdapter(data, this)
        rv?.layoutManager = LinearLayoutManager(this)

    }


    class MyAdapter(private val data: List<String>, private val context: Context) :
        RecyclerView.Adapter<RecyclerView.ViewHolder>() {
        override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): RecyclerView.ViewHolder {
            return MyViewHolder(
                LayoutInflater.from(parent.context).inflate(R.layout.item_txt, parent, false)
            )
        }

        override fun onBindViewHolder(holder: RecyclerView.ViewHolder, position: Int) {
            (holder as MyViewHolder).textView.text = data[position]
        }

        override fun getItemCount(): Int {
            return data.size
        }

        class MyViewHolder(item: View) : RecyclerView.ViewHolder(item) {
            val textView: TextView = item.findViewById(R.id.tv_item)
        }

    }
}